
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QMainWindow>
#include <QPixmap>
#include <QImage>
#include <QPainter>
#include <mypushbtn.h>




#include <QTimer>
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    this->setWindowTitle("snake");

    //菜单栏的初始化
    connect(ui->actionexit, &QAction::triggered, this, &MainWindow::close);

    gm = new gmsc;

    //开始按钮
    mypushbtn * stbtn = new mypushbtn(":/start.png");
    stbtn->setParent(this);
    stbtn->move(this->width() / 2 - stbtn->width() / 2, this->height() * 0.7);
    connect(stbtn, &QPushButton::clicked, [=](){
        stbtn->zoomup();
        stbtn->zoomdown();

        QTimer::singleShot(450, this, [=](){
            this->hide();
            //游戏场景

            gm->show();

        });


    });
    //connect(gm, &QWidget::);
}

MainWindow::~MainWindow()
{
    delete ui;
}


void MainWindow::paintEvent(QPaintEvent *)
{
    QPainter painter(this);
    QPixmap pix;
    pix.load(":/grass.png");
    painter.drawPixmap(0, 0, this->width(), this->height(), pix);
    //img.load(":/start.png");
//    for (int i=0; i<img.width(); ++i) {
//        for (int j=0; j<img.height(); ++j) {

//            QRgb = rgb = img.pixel(i, j);
//            if(rgb==origColor.rgb())
//            {
//                img.setPixel(i, j, destColor.rgb)
//            }
//        }
//    }
    //painter.drawImage(100, 100, img);
    //mypushbtn * pushbtn = new mypushbtn(":/start.png");

}
